package com.getword;


import com.getword.dao.CityDao;
import com.getword.domain.City;
import com.getword.domain.SchoolType;
import com.getword.mongodao.CityRepository;
import com.getword.mongodao.SchoolRepository;
import com.getword.mongodao.SchoolTypeRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class InitData {
    @Autowired
    private CityDao cityDao;

    @Autowired
    private CityRepository cityRepository;

    @Autowired
    private SchoolTypeRepository schoolTypeRepository;


    @Test
    public void initCity() {
        List<City> cities = cityDao.select(0);
        cityRepository.saveAll(cities);
        for (int i = 1; cities != null && cities.size() > 0; i++) {
            cities = cityDao.select(200*i);
            cityRepository.saveAll(cities);
        }
    }

    @Test
    public void initSchoolType(){
        String[] ts = {
                "公立小学",
                "公立中学",
                "公立九年一贯制",
                "公立十二年一贯制",
                "私立小学",
                "私立中学",
                "私立九年一贯制",
                "私立十二年一贯制",
                "培训机构"
        };
        for(String t : ts){
            SchoolType schoolType = new SchoolType();
            schoolType.setName(t);
            schoolTypeRepository.save(schoolType);
        }
    }
}
